package datatypes;

import tools.Converter;
import tools.settings.Settings;
import tools.settings.SettingsAdapter;

public class Technology {
	
	private String techn;
	private String plmodel_macro;
	private String plmodel_micro; 
	private double maxInputPower_macro;
	private double maxInputPower_micro; 
	//Mobile station antenna gain 
	private double MS_gain;
	//Base station antenna gain default 
	private double BS_gain_default_macro;
	private double BS_gain_default_micro; 
	//Number of MIMO Tx antennas 
	private int nTx; 
	//Number of MIMO Rx antennas 
	private int nRx; 
	//BS cyclic combining gain 
	private int cyclicGain; 
	private int aas; 
	//BS soft handover gain 
	private double shg; 
	//Feeder loss BS 
	private double flbs; 
	//Feeder loss MS 
	private double flms;
	//Fade margin 
	private double fm; 
	//Cell interference margin 
	private double cim;
	//Building penetration loss
	private double bpl; 
	//Carrier frequency 
	private int freq; 
	private double userspeed;
	private double doppler;
	//Bandwidth
	private double BW; 
	//ReceiverSNR 
	private double RxSNR;
	//Noise figure 
	private double nf; 
	//implementation loss MS 
	private double il; 
	//Height MS 
	private double height_MS; 
	//Shadowing requirement 
	private double shadow;
	//Standard deviation building 
	private double sdb; 
	//Sampling factor: not for UMTS and HSPA 
	private double n;
	//Used subcarriers: not for UMTS and HSPA 
	private int used; 
	//Total subcarriers: not for UMTS and HSPA 
	private int total;
	//Guard period: only for UMTS and HSPA 
	private double GP;
	//Target load: only for UMTS and HSPA 
	private double TL; 
	//users: only for UMTS and HSPA
	private int users; 
	//chip rate: only for UMTS and HSPA 
	private double cr; 
	//bit rate: only for UMTS and HSPA 
	private double bitrate;
	
	//Typical height BS macro and micro
	private double BS_height_macro; 
	private double BS_height_micro; 
	
	public Technology(SettingsAdapter sa){
		Settings settings = sa.getSettings();

		techn = settings.getSettingsValue("technology");
		plmodel_macro = settings.getSettingsValue("pathlossmodel_macro");
		plmodel_micro = settings.getSettingsValue("pathlossmodel_micro"); 
		maxInputPower_macro = Converter.dBm2W(Double.parseDouble(settings.getSettingsValue("maxInputPower_dBm_macro")));
		maxInputPower_micro = Converter.dBm2W(Double.parseDouble(settings.getSettingsValue("maxInputPower_dBm_micro")));
		MS_gain = Double.parseDouble(settings.getSettingsValue("MS_atennagain"));
		BS_gain_default_macro = Double.parseDouble(settings.getSettingsValue("BS_antennagain_default_macro"));
		BS_gain_default_micro = Double.parseDouble(settings.getSettingsValue("BS_antennagain_default_micro"));
		nTx = Integer.parseInt(settings.getSettingsValue("MIMO_Tx"));
		nRx = Integer.parseInt(settings.getSettingsValue("MIMO_RX"));
		cyclicGain = Integer.parseInt(settings.getSettingsValue("cyclicgain")); 
		aas = Integer.parseInt(settings.getSettingsValue("AAS")); 
		shg = Double.parseDouble(settings.getSettingsValue("MS_softhandovergain"));
		flbs = Double.parseDouble(settings.getSettingsValue("BS_feederloss"));
		flms = Double.parseDouble(settings.getSettingsValue("MS_feederloss")); 
		fm = Double.parseDouble(settings.getSettingsValue("fademargin"));
		cim = Double.parseDouble(settings.getSettingsValue("cellinterferencemargin"));
		bpl = Double.parseDouble(settings.getSettingsValue("buildingpenetrationloss")); 
		freq = Integer.parseInt(settings.getSettingsValue("frequency"));
		userspeed = Double.parseDouble(settings.getSettingsValue("userspeed"));
		doppler = Double.parseDouble(settings.getSettingsValue("dopplermargin"));
		BW = Double.parseDouble(settings.getSettingsValue("bandwidth")); 
		RxSNR = Double.parseDouble(settings.getSettingsValue("RxSNR"));
		nf = Double.parseDouble(settings.getSettingsValue("noisefigure"));
		il = Double.parseDouble(settings.getSettingsValue("implementationloss"));
		height_MS = Double.parseDouble(settings.getSettingsValue("heightMS"));
		shadow = Double.parseDouble(settings.getSettingsValue("shadowmargin"));
		sdb = Double.parseDouble(settings.getSettingsValue("standardDeviationBuilding"));
		
		BS_height_macro = Double.parseDouble(settings.getSettingsValue("BS_height_macro")); 
		BS_height_micro = Double.parseDouble(settings.getSettingsValue("BS_height_micro"));
		
		if(!(techn.equalsIgnoreCase("UMTS") || techn.equalsIgnoreCase("HSPA"))){
			n = Double.parseDouble(settings.getSettingsValue("samplingfactor"));
			used = Integer.parseInt(settings.getSettingsValue("usedsubcarriers"));
			total = Integer.parseInt(settings.getSettingsValue("totalsubcarriers"));
		}else{
			GP = Double.parseDouble(settings.getSettingsValue("guardperiod"));
			TL = Double.parseDouble(settings.getSettingsValue("targetload"));
			users = Integer.parseInt(settings.getSettingsValue("users"));
			cr = Double.parseDouble(settings.getSettingsValue("chiprate"));
			bitrate = Double.parseDouble(settings.getSettingsValue("bitrate"));
			used = 1; 
			total = 1; 
			n = cr/BW;
			
			used = 1;
			total = 1;
		}
	}
	
	public String getTechnology(){
		return techn; 
	}
	
	public String getTechnologyAlternativeName(){
		String tmp = techn; 
		if (tmp.contains("802.16"))
			tmp = "WiMAX";
		return tmp; 
	}

	public String getPathLossModel(String type) {
		if (type.equalsIgnoreCase("macro"))
			return plmodel_macro;
		else if (type.equalsIgnoreCase("micro"))
			return plmodel_micro; 
		else return ""; 
	}
	
	// returns maximum input power in Watt!
	public double getMaxInputPower(String type){
		if(type.equalsIgnoreCase("macro")) 
			return maxInputPower_macro; 
		else if(type.equalsIgnoreCase("micro"))
			return maxInputPower_micro; 
		else return 0; 
	}

	public double getMSAntennaGain() {
		return MS_gain;
	}
	
	public double getBSAntennaGain_default(String type){
		if(type.equalsIgnoreCase("macro"))
			return BS_gain_default_macro; 
		else if (type.equalsIgnoreCase("micro"))
			return BS_gain_default_micro; 
		else return 0; 
	}
	
	public int getMIMOTx(){
		return nTx;
	}
	
	public int getMIMORx(){
		return nRx;
	}
	
	public int getCyclicGain(){
		return cyclicGain; 
	}
	
	public int getAAS(){
		return aas; 
	}
	
	public double getSoftHandoverGain(){
		return shg;
	}
	
	public double getBSFeederLoss(){
		return flbs; 
	}
	
	public double getMSFeederLoss(){
		return flms;
	}
	
	public double getFadeMargin(){
		return fm; 
	}
	
	public double getCellInterferenceMargin(){
		return cim;
	}
	
	public double getBuildingPenetrationLoss(){
		return bpl;
	}
	
	public int getFrequency(){
		return freq; 
	}
	
	public double getUserspeed(){
		return userspeed; 
	}
	
	public double getDopplerMargin(){
		return doppler; 
	}
	
	public double getBandwidth(){
		return BW;
	}
	
	public double getRxSNR(){ 
		return RxSNR; 
	}
	
	public double getNoiseFigure(){
		return nf; 
	}
	
	public double getImplementationLoss(){
		return il; 
	}
	
	public double getMSHeight(){
		return height_MS; 
	}
	
	public double getShadowMargin(){
		return shadow; 
	}
	
	public double getStandardDeviationBuilding(){
		return sdb; 
	}
	
	public double getSamplingFactor(){
		return n; 
	}
	
	public double getUsedSubcarriers(){
		return used; 
	}
	
	public double getTotalSubcarriers(){
		return total; 
	}
	
	public double getGuardPeriod(){
		return GP; 
	}
	
	public double getTargetLoad(){
		return TL; 
	}
	
	public double getUsers(){
		return users; 
	}
	
	public double getChipRate(){
		return cr; 
	}
	
	public double getBitRate(){
		return bitrate; 
	}
	
	public double getBSHeight(String type){ 
		if(type.equalsIgnoreCase("micro")) return BS_height_micro; 
		else return BS_height_macro; 
	}
}
